const clone = (obj) => {
  if (obj instanceof Object) {
    let tmp = obj instanceof Array ? [] : {};
    for (const key in obj) {
      tmp[key] = clone(obj[key]);
    }
    return tmp;
  } else {
    return obj;
  }
};

console.dir(clone({ id: 1, obj: { id: 2 } }));
